//need the two following lines of code or else whole thing will break
varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;
/*
 Notes:
 
 lowp = low precison, mediump = medium precision, highp = high precision
 lowp = faster preformence
 highp = slower preformance but higher precision
 */


//The Daltonize algorithm implemented as a fragment shader
void main()
{
   
//grab the rgb values here
lowp vec3 pixcol = texture2D(inputImageTexture, textureCoordinate).rgb;

//RGB to LMS transform:  important in mat3 every three successive group of numbers represents a coloum NOT ROW.
lowp vec3 RGB_Colors = vec3(pixcol.r, pixcol.g, pixcol.b);
mediump mat3 RGB2LMS = mat3(17.8824, 3.45565, .0299566, 43.5262, 27.1554, .0184309, 4.1193, 3.86714, 1.46709);
lowp vec3 LMS_RGB_Values = RGB2LMS * RGB_Colors;

//mapping of normal cone responses LMS to protanope cone responses
mediump mat3 LMS2ProtaopeConeResponseMatrix = mat3(0.0, 0.0, 0.0, 2.02344, 1.0, 0.0, -2.52581, 0.0, 1.0);
lowp vec3 LP_MP_SP = LMS2ProtaopeConeResponseMatrix*LMS_RGB_Values;

//now calcuate colour precieved by protanope
mediump mat3 RGBProtanopeColorPerception = mat3(0.0809444479, -0.0102485335, -0.000365296938, -0.130504409, 0.0540193266, -0.00412161469, 0.116721066, -0.113614708, 0.693511405);
lowp vec3 RP_GP_BP = RGBProtanopeColorPerception*LP_MP_SP;

//shoot back the pixels the protanopes sees to the fragment shader + an alpha
gl_FragColor = vec4(RP_GP_BP,1.0);
}